package com.shujia.udf;

import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;

import java.util.Arrays;

public class UdfDemo1 extends GenericUDF {
    private String res = "";
    private String  description = "";
    @Override
    public ObjectInspector initialize(ObjectInspector[] objectInspectors) {
        return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    }

    @Override
    public Object evaluate(DeferredObject[] deferredObjects) {
        StringBuilder stringBuilder = new StringBuilder();
        for (DeferredObject deferredObject : deferredObjects) {
            String string = deferredObject.toString();
            stringBuilder.append(string);
        }
        res = res+stringBuilder;
        return res;
    }

    @Override
    public String getDisplayString(String[] strings) {
        description ="这是自定义函数";
        return description;
    }
}
